﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports NHibernate
Imports SIAVU.Dominio
Imports NHibernate.Criterion

Namespace Persistencia
    Public Class ActividadPersistencia

        Public Sub getById(ByRef oActividad As Actividad)
            Dim session As ISession = Nothing
            Try
                session = NHibernateHelper.OpenSession
                oActividad = DirectCast(session.Get(GetType(Actividad), oActividad.ActividadID), Actividad)
            Catch ex As Exception
                Throw
            Finally
                session.Close()
            End Try
        End Sub

        'Public Sub getById(ByRef oActividad As Actividad, ByRef Session As ISession)
        '    Try
        '        oActividad = DirectCast(Session.Get(GetType(Actividad), oActividad.ActividadID), Actividad)
        '    Catch ex As Exception
        '        Throw
        '    End Try
        'End Sub

        Public Sub Actualizar(ByVal oActividad As Actividad)
            Dim session As ISession = NHibernateHelper.OpenSession()
            Dim oTransaccion As ITransaction = Nothing
            Try
                oTransaccion = session.BeginTransaction()
                oTransaccion.Begin()

                session.SaveOrUpdate(oActividad)
                oTransaccion.Commit()

            Catch ex As Exception
                oTransaccion.Rollback()
                Throw

            Finally
                session.Close()
            End Try
        End Sub

        'Public Sub ActualizarSinTransaccion(ByVal oActividad As Actividad)
        '    Dim session As ISession = NHibernateHelper.OpenSession()
        '    Dim oTransaccion As ITransaction = Nothing

        '    Try
        '        oTransaccion = session.BeginTransaction()
        '        oTransaccion.Begin()

        '        session.SaveOrUpdate(oActividad)

        '        oTransaccion.Commit()

        '    Catch ex As Exception
        '        oTransaccion.Rollback()
        '        Throw

        '    Finally
        '        session.Close()
        '    End Try
        'End Sub

        Public Sub ActualizarSinTransaccion(ByVal oActividad As Actividad, ByRef session As ISession)
            Try
                session.SaveOrUpdate(oActividad)

            Catch ex As Exception
                Throw
            End Try
        End Sub

    End Class

End Namespace

